package test;

public class PubsubMain {
    public static void main(String[] args) {
        String[] channels = {"channel1", "channel2", "channel3"};
        
        // 创建并启动多个订阅者
        for (String channel : channels) {
            new Thread(() -> {
                Subscriber subscriber = new Subscriber(channels);
                subscriber.subscribe();
                System.out.println("subscribed");
            }).start();
        }

        // 发布消息
        Publisher publisher = new Publisher();
        for (int i = 0; i < 2; i++) {
            publisher.publish("channel1", "Hello to Channel 1: " + i);
            publisher.publish("channel2", "Hello to Channel 2: " + i);
            publisher.publish("channel3", "Hello to Channel 3: " + i);
        }
    }
}
